package com.control;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.db.DBConnect;
import com.model.Building;

public class BuildingControl {

	/**
	 * 获取所有寝室楼的信息
	 * @return
	 */
	public ArrayList<Building> getBuildingList() {
		DBConnect dbc = new DBConnect();
		ArrayList<Building> buildinglist = new ArrayList<Building>();
		String sql="{call getBuildingList()}";
		/*String sql = "select * from building";*/
		try	{
			CallableStatement stmt = dbc.getConnection().prepareCall(sql); 
			ResultSet rs = stmt.executeQuery();
			while(rs.next()) {
				Building building = new Building();
				building.setBuilding_id(rs.getInt("building_id"));
				building.setBuilding_name(rs.getString("building_name"));
				buildinglist.add(building);
			}
			return buildinglist;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		} finally {
			dbc.close();		
		}
	}
}
